package cn.belong.jk.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import cn.belong.jk.entity.Factory;
import cn.belong.jk.service.FactoryService;

@Controller
@RequestMapping("factory")
public class FactoryController extends BaseController{

	@Resource
	private FactoryService factoryService;
	
    //列表  
    @RequestMapping("/list.action")  
    public String list(Model model){  
        List<Factory> dataList=factoryService.find(null);  
        model.addAttribute("dataList", dataList);//将数据传递到页面  
      
        return "/baseinfo/factory/jFactoryList.jsp";//转向页面  
    }  
    
  //转向新增页面  
    @RequestMapping("/tocreate.action")  
    public String tocreate(){  
        return "/baseinfo/factory/jFactoryCreate.jsp";  
    }  
          
    //进行新增  
    @RequestMapping("/insert.action")  
    public String insert(Factory factory){  
        factoryService.insert(factory);  
        return "redirect:/factory/list.action";//转向列表action  
    }  
    
    
  //转向修改界面  
    @RequestMapping("/toupdate.action")  
    public String toupdate(String id,Model model){  
        Factory obj=factoryService.get(id);  
        model.addAttribute("obj", obj);  
        return "/baseinfo/factory/jFactoryUpdate.jsp";  
    }  
          
          
    //修改保存  
    @RequestMapping("/update.action")  
    public String update(Factory factory){  
        factoryService.update(factory);  
        return "redirect:/factory/list.action";  
    }  
    
  //删除一个  
    @RequestMapping("/deleteById.action")  
    public String deleteById(String id){  
        factoryService.deleteById(id);  
        return "redirect:/factory/list.action";  
    }  
          
    //删除多条  
    @RequestMapping("/delete.action")  
    public String delete(@RequestParam("id") String[] ids){  
        factoryService.delete(ids);  
        return "redirect:/factory/list.action";  
    }  
    
  //查看  
    @RequestMapping("/toview.action")  
    public String toview(String id,Model model){  
        Factory obj=factoryService.get(id);  
        model.addAttribute("obj",obj);  
        return "/baseinfo/factory/jFactoryView.jsp";  
    }  
    
  //批量启用  
    @RequestMapping("/start.action")  
    public String start(@RequestParam("id") String[] ids){  
        factoryService.start(ids);  
        return "redirect:/factory/list.action";  
              
    }  
          
    //批量停用  
    @RequestMapping("/stop.action")  
    public String stop(@RequestParam("id") String[] ids){  
        factoryService.stop(ids);  
        return "redirect:/factory/list.action";     
    }  
	
}
